package com.wjboot.wxminiapp.service.impl;

import cn.binarywang.wx.miniapp.api.WxMaService;
import com.wjboot.wxminiapp.service.WxCheckService;
import com.wjboot.wxminiapp.util.SenInfoCheckUtil;
import lombok.RequiredArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@RequiredArgsConstructor
@Service
public class WxCheckServiceImpl implements WxCheckService {
    private final WxMaService wxMaService;

    @Override
    public Boolean checkContent(String content) throws WxErrorException {
        String accessToken = getAccessToken();
        return SenInfoCheckUtil.cotentFilter(accessToken, content);
    }

    @Override
    public Boolean checkImage(MultipartFile multipartFile) throws WxErrorException {
        String accessToken = getAccessToken();
        return SenInfoCheckUtil.imgFilter(multipartFile, accessToken);
    }

    private String getAccessToken() throws WxErrorException {
        return wxMaService.getAccessToken();
    }
}
